package com.li.client;

import com.li.annotation.Component;

import java.lang.reflect.Field;

public class ReflectAnnotation {
    public static void main(String[] args) throws Exception {
        //通过反射机制怎么读取注解
        Class<?> clazz = Class.forName("com.li.bean.User");
        //判断类上面有没有这个注解
        if (clazz.isAnnotationPresent(Component.class)) {
            //获取类上的注解信息
            Component annotation = clazz.getAnnotation(Component.class);
            System.out.println(annotation.value());
        }
        //获取字段上的注解信息
        Field field = clazz.getDeclaredField("name");
        if (field.isAnnotationPresent(Component.class)) {
            Component annotation = field.getAnnotation(Component.class);
            System.out.println(annotation.value());
        }

    }
}
